<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <custom-user :username="name" :cities="['beijing','taiyuan']" :insterts="['吃饭','睡觉']"></custom-user>
  </div>

  <script type="text/template" id="temp">
    <div>用户名：{{username}}

      年龄：{{age}}
    </div>
  </script>

  <script>


    Vue.component('custom-user', {
      props: {
        username: {
          type: String,
          required: true
        },
        cities: Array,
        age: {
          type: Number,
          //当此属性不设置的时候，默认值
          default: 30
        },
        insterts: {
          validator(val) {
            return val.indexOf('吃饭') > -1;
          }
        }

      },
      template: '#temp',
      mounted() {
        console.log('username:', this.username)
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {
        name: 'admin'
      }
    })


    // var vm = new Vue({
    //   el: "#app",
    //   components: {
    //     'custom-user': {
    //       props:['username'],
    //       // props:{
    //       //   username:String
    //       // },
    //       template: '#temp',
    //       mounted(){
    //         console.log('username:',this.username)
    //       }
    //     }
    //   }
    // })

  </script>

</body>

</html>